package alejandro.castro.extras;

import java.io.BufferedInputStream;
import java.io.InputStream;

import javazoom.jl.player.Player;
import javazoom.jl.player.advanced.AdvancedPlayer;

public class MusicPlayerThread extends Thread {

	private InputStream fis = null;
	private BufferedInputStream bis = null;
	public Player player;
	AdvancedPlayer player2;

	@Override
	public void run() {
		super.run();
		play();
	}

	public void play() {
		try {
			fis = getClass().getClassLoader().getResourceAsStream("sounds/theme.mp3");
			bis = new BufferedInputStream(fis);
			player = new Player(bis);
			player.play();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				fis.close();
			} catch (Exception e) {
			}
			try {
				bis.close();
			} catch (Exception e) {
			}
		}
	}

	public void pause() {
		try {
			this.player.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		try {
			fis.close();
		} catch (Exception e) {
		}
		try {
			bis.close();
		} catch (Exception e) {
		}
	}

}
